package com.tencet.servlet;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.tencet.entity.OpenAccount;
import com.tencet.entity.Personal;
import com.tencet.service.Impl.PersonalServiceImpl;
import com.tencet.service.PersonalService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author: King
 * @date: 2022/7/21 14:19
 * @description:
 */
@WebServlet("/personalList")
public class PersonalServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //解决中文乱码
        resp.setContentType("text/html;charset=utf-8");
        //获取个人中心的电话号
//        Personal personal1 = new Personal();
//        personal1.setP_phone("1311111111");
//        personal1.setP_name("3412312");

//        req.getSession().setAttribute("personal1",personal1);
        OpenAccount openAccount = (OpenAccount) req.getSession().getAttribute("openAccount");


        String pPhone = openAccount.getPhone();
        String name = openAccount.getName();
        String idNumber = openAccount.getIdNumber();
        String payPassword = openAccount.getPayPassword();

        Personal personal1 = new Personal();
        personal1.setP_phone(pPhone);
        personal1.setP_name(name);
        personal1.setId_card(idNumber);
        personal1.setPassword(payPassword);


        PersonalService personalService= new PersonalServiceImpl();
        Personal personal = personalService.findALL(pPhone);
//        System.out.println(personal);
//        boolean result = personalService.registPersonal(personal1);


        //接受参数详细地址
//        String detailed = req.getParameter("detailed");
//        String pPhone1 = personal1.getP_phone();
        //调用service
//        PersonalService personalService1= new PersonalServiceImpl();
//        boolean update = personalService1.registPersonal1(detailed,pPhone1);
        //写回到页面
        //resp.getWriter().write(update+"");
//        if (update){
//            resp.getWriter().write("y");
//        }else {
//            resp.getWriter().write("n");
//        }

        //将对象转换成json格式



        ObjectMapper om = new ObjectMapper();
        String s = om.writeValueAsString(personal);
//        System.out.println("s = " + s);
//        resp.getWriter().write(s + "");
        resp.getWriter().write(s);
    }

}